from selenium import webdriver
import json
import os

driver = 0
path = os.path.join(os.getcwd(), './html_vue3/project/dist/index.html')


def addData(data):
    global driver
    if driver == 0:
        chromeOptions = webdriver.ChromeOptions()
        chromeOptions.add_experimental_option("detach", True)
        driver = webdriver.Chrome(options=chromeOptions)
        # driver.get("http://localhost:8080/")
        driver.get("file://" + path)
        driver.minimize_window()
    driver.execute_script(f'''addData({json.dumps(data)})''')


def finishAdd():
    global driver
    driver.maximize_window()

# data example
# data = {
#     'id': "001",
#     'name': "a12",
#     'type': "type a",
#     'department': "数字化部",
#     'company': "联通",
#     'property': "red",
#     'ddl': "2021-11-1",
#     'person': "张三",
#     'tel': "13423456789",
#     'money': "5000",
#     'target': "基站100%",
#     'isInfo': "是",
# }
